#include "Player.h"

static Player *player = nullptr;

Player* Player::getInstance() {
	if (player == nullptr) {
		player = new Player();
		player->initPlayer();
	}
	return player;
}

void Player::initPlayer() {
	m_level = USERDEFAULT->getIntegerForKey(LEVEL_KEY);
	m_jewel = USERDEFAULT->getIntegerForKey(JEWEL_KEY);
	m_gold = USERDEFAULT->getIntegerForKey(GOLD_KEY);
	m_hp = USERDEFAULT->getIntegerForKey(HP_KEY);
	m_mp = USERDEFAULT->getIntegerForKey(MP_KEY);
}

void Player::setLevel(int level) {
	m_level = level;
	USERDEFAULT->setIntegerForKey(LEVEL_KEY, level);
	USERDEFAULT->flush();
}

void Player::setJewel(int jewel) {
	m_jewel = jewel;
	USERDEFAULT->setIntegerForKey(JEWEL_KEY, jewel);
	USERDEFAULT->flush();
}

void Player::setGold(int Gold) {
	m_gold = Gold;
	USERDEFAULT->setIntegerForKey(GOLD_KEY, Gold);
	USERDEFAULT->flush();
}

void Player::setHP(int HP) {
	m_hp = HP;
	USERDEFAULT->setIntegerForKey(HP_KEY, HP);
	USERDEFAULT->flush();
}

void Player::setMP(int MP) {
	m_mp = MP;
	USERDEFAULT->setIntegerForKey(MP_KEY, MP);
	USERDEFAULT->flush();
}
